package tests;

import org.openqa.selenium.By;

import java.io.IOException;

/**
 * 测试用户注册模块
 */

public class Register extends Login {


    /**
     * 从登录界面跳转注册页面
     */
    public Register() {
        driver.findElement(By.cssSelector("body > div.page.page-center > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3 > a")).click();
    }

    /**
     * 检查注册页面是否已经加载出来
     */
    public void registerIsRight() throws IOException {
        getScreenShot(Login.class.getName(),"registerIsRight");
        driver.findElement(By.cssSelector("#signUpForm > div > h2"));
        driver.findElement(By.cssSelector("#passwordRepeat"));
    }


    /**
     * 注册失败 -- 未勾选协议
     */
    public void error1() throws IOException {

        //1.清空输入框
        driver.navigate().refresh();

        //2.填写注册信息
        driver.findElement(By.cssSelector("#username")).sendKeys("test");
        driver.findElement(By.cssSelector("#nickname")).sendKeys("test");
        driver.findElement(By.cssSelector("#password")).sendKeys("test");
        driver.findElement(By.cssSelector("#passwordRepeat")).sendKeys("test");
        driver.findElement(By.cssSelector("#submit")).click();
        //3.不勾选协议框

        //getScreenShot(Register.class.getName());

        //4.检查页面
        String expect = driver.getTitle();
        assert expect.equals("成人论坛-用户注册");

    }

    /**
     * 注册失败 -- 用户已存在
     */
    public void error2() {
        //1.清空输入框
        driver.navigate().refresh();
        //2.填写注册信息 -- 用户已存在
        driver.findElement(By.cssSelector("#username")).sendKeys("ljy");
        driver.findElement(By.cssSelector("#nickname")).sendKeys("test");
        driver.findElement(By.cssSelector("#password")).sendKeys("test");
        driver.findElement(By.cssSelector("#passwordRepeat")).sendKeys("test");
        driver.findElement(By.cssSelector("#policy")).click();
        driver.findElement(By.cssSelector("#submit")).click();

        //4.检查页面
        String expect = driver.getTitle();
        assert expect.equals("成人论坛-用户注册");

    }


    /**
     * 注册成功
     */
    public void registerSuc() throws IOException {
        //getScreenShot(Register.class.getName()+".registerSuc()");
        //1.清空输入框
        driver.navigate().refresh();

        //2.填写注册信息
        driver.findElement(By.cssSelector("#username")).sendKeys("test");
        driver.findElement(By.cssSelector("#nickname")).sendKeys("test");
        driver.findElement(By.cssSelector("#password")).sendKeys("test");
        driver.findElement(By.cssSelector("#passwordRepeat")).sendKeys("test");
        driver.findElement(By.cssSelector("#policy")).click(); //勾选协议框
        driver.findElement(By.cssSelector("#submit")).click();

        //3.检查
        String expect = driver.getTitle();
        assert expect.equals("学识论坛-用户登陆");
        driver.findElement(By.cssSelector("#username"));
    }

}
